using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    /// <summary>
    /// Move to special purpose register
    /// </summary>
    public class Mts : Instruction
    {
        private uint specialPurposeRegister;

        public override int CycleCount
        {
            get { return 1; }
        }

        public Mts()
            : base("mts")
        {
        }

        public override void Set(uint address, uint value)
        {
            base.Set(address, value);
            specialPurposeRegister = value & 0x3;
        }

        /// <summary>
        /// Copies the contents of register rD into the MSR or FSR.
        /// </summary>
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            // read register
            uint sa = MicroblazeComponent.ReadRegister(SourceRegisterA);

            // write special purpose register
            MicroblazeComponent.WriteSpecialPurposeRegister(specialPurposeRegister, sa);
        }

        public override string ToString()
        {
            return String.Format("mfs r{0}, r{1}",
              specialPurposeRegister,
              SourceRegisterA
            );
        }
    }
}
